//
//  propoty.swift
//  fsapp
//
//  Created by zguang on 17/7/27.
//  Copyright © 2017年 huangshengjie. All rights reserved.
//

import Foundation
import UIKit
import Alamofire
import AdSupport

let idfa = ASIdentifierManager.shared().advertisingIdentifier.uuid
let SCREEN_HEIGHT = UIScreen.main.bounds.height


let LOGIN_API_URL = "http://dahan-api.heiyou.net/index.php/home/user/"
//let Index_API_URL =

let naviColor = UIColor.init(red: 0, green: 105/255, blue: 193/255, alpha: 1)
let lineColor = UIColor.init(red: 221/255, green: 221/255, blue: 221/255, alpha: 1)
let myRed = UIColor.init(red: 235/255, green: 24/255, blue: 116/255, alpha: 1)
let title2color = UIColor.init(red: 122/255, green: 122/255, blue: 122/255, alpha: 1)
let backColor = UIColor.init(red: 241/255, green: 241/255, blue: 242/255, alpha: 1)

func height(_ height: Double) -> CGFloat{
   return CGFloat(height/1334)*(SCREEN_HEIGHT)
}
func width(_ width: Double) -> CGFloat{
    return CGFloat(width/750)*(SCREEN_WIDTH)
}
func getWidth(width :Double) -> CGFloat {
    return  CGFloat(width/750)*(SCREEN_WIDTH)
}
func getHeight(_ height:Double)->CGFloat{
    return CGFloat(height/1334)*(SCREEN_HEIGHT)
}

func loadCookies() {
    guard let cookieArray = UserDefaults.standard.array(forKey: "savedCookies") as? [[HTTPCookiePropertyKey: Any]] else { return }
    for cookieProperties in cookieArray {
        if let cookie = HTTPCookie(properties: cookieProperties) {
            print(cookie)
            HTTPCookieStorage.shared.setCookie(cookie)
        }
    }
}

func saveCookies(response: DataResponse<Any>) {
    let headerFields = response.response?.allHeaderFields as! [String: String]
    let url = response.response?.url
    let cookies = HTTPCookie.cookies(withResponseHeaderFields: headerFields, for: url!)
    var cookieArray = [[HTTPCookiePropertyKey: Any]]()
    for cookie in cookies {
        cookieArray.append(cookie.properties!)
    }
    UserDefaults.standard.set(cookieArray, forKey: "savedCookies")
    UserDefaults.standard.synchronize()
    print(cookies)
}





/*
func getCommit(){
    
    let url = "http://dahan-api.heiyou.net/index.php/home/video/getComment"
    let paramdic = ["video_id":self.videoId]
    Alamofire.request( url, method: .post, parameters: paramdic).responseJSON{ response
        in
        
        if let al = response.response{
            
        }else{
            let alert = UIAlertView(title: "网络连接失败", message: "请稍后重试", delegate: nil, cancelButtonTitle: "知道了")
            alert.show()
        }
        
        //response serialization
        if let JSON2 = response.result.value {
            let js = JSON(JSON2)
            print(js)
            if js["status"] == 200{
                if js["result"].count != 0{
                    for i in 0...js["result"].count-1{
                        
                    }
                }
                
            }
            
        }
    }
    
}
    */
